import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    homeNavList: [],
    needData: {},
    videoUrl: null,
    videoDetailId: null,
    allnav: [],
    creatorInsList:[],
    creatortitle:'',
    creatorFilter:{},
    currentTime:null,
      duration:null,
      currentTime:null,
      newcurrentTime:null,
      bigCurrentTime:null,
      bigCurrentId:null,
      attentionList:[],
  },
  getters: {},
  mutations: {
    //首页选项卡导航栏
    addHomeNavList(state, value) {
      state.homeNavList = value
      state.homeNavList = state.homeNavList.value.filter(
        (i) => i.type !== 'feed'
      )
    },
    // 首页渲染的数据
    homeViewData(state, payload) {
      state.needData = payload.value;
    },
    AllNav(state, payload) {
      state.allnav = payload.value
    },
    upCreatorIns(state,payload){
      state.creatorInsList=payload.list;
      state.creatortitle=payload.title;
      state.creatorFilter=payload.filter;
    },
    upduration(state,payload){
      state.duration=payload.value;
    },
    upcurrentTime(state,payload){
      state.currentTime=payload.value*1;
    },
    upnewcurrentTime(state,payload){
      state.newcurrentTime=payload.value
    },
    bigCardCurrent(state,payload){
      state.bigCurrentTime=payload.value
      state.bigCurrentId=payload.id
    },
    //关注用户
    addAttention(state,payload){
      if(state.attentionList.length){
        state.attentionList.forEach((a,b)=>{
          if(a!=payload.id){
            state.attentionList.push(payload.id)
          }else{
            state.attentionList.splice(b,b+1)
          }
        })
      }else{
        state.attentionList.push(payload.id)
      }
      state.attentionList=state.attentionList.filter((a,b)=>{
        if(a!=state.attentionList[b+1]){
          return a
        }
      })
      window.localStorage.setItem("attentionList",JSON.stringify(state.attentionList))
      console.log(state.attentionList);
    },
    //初始关注
    createdAttention(state,payload){
      state.attentionList=payload.arr?payload.arr:[]
    }
  },
  actions: {},
  modules: {},
})